package com.technology.education.ui.common.information

import androidx.lifecycle.MutableLiveData
import com.technology.education.ext.toast
import com.technology.education.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.StringObservableField
import me.hgj.jetpackmvvm.ext.request

class CompleteInfoViewModel : BaseViewModel() {
    val name = StringObservableField()
    val age = StringObservableField()
    val address = StringObservableField()
    var city = ""
    var province = ""
    var district = ""
    val result = MutableLiveData<Boolean>()

    fun commit() {
        if (name.get().isEmpty()) {
            toast("请输入您的姓名")
            return
        }
        if (age.get().isEmpty()) {
            toast("请输入您的年龄")
            return
        }
        if (address.get().isEmpty()) {
            toast("请选择您所在的城市")
            return
        }
        request({
            apiService.updateBaseInfo(
                hashMapOf(
                    "address" to "",
                    "age" to age.get(),
                    "city" to city,
                    "district" to district,
                    "name" to name.get(),
                    "province" to province
                )
            )
        }, success = {
            result.postValue(true)
        }, error = {
            toast(it.errorMsg)
        }, isShowDialog = true)
    }

}